<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>期刊管理</title>
    <!--<script type="text/javascript" src="/libms/lib/js/jquery-3.2.1.min.js"></script>-->
    <!--<script type="text/javascript" src="/libms/lib/js/bootstrap.min.js"></script>-->

    <!--<script src="/libms/lib/layui/layui.js" type="text/javascript"></script>-->
    <!--<link rel="stylesheet" href="/libms/lib/layui/css/layui.css">-->
    <!--<link rel="stylesheet" href="/libms/lib/css/bootstrap.min.css">-->

    <script type="text/javascript" src="../app/js/bookman.js"></script>
    <link rel="stylesheet" href="../app/css/tablegroup.css">
</head>
<body>
<div class="container">
    <div class="tgroup">
        <div class="form form-inline">
            <input class="form-control" type="text" name="" id="username" placeholder="用户名">
            <input class="form-control" type="text" name="" id="name" placeholder="姓名">
            <input class="form-control" type="text" name="" id="phone" placeholder="手机号">
            <!--<input class="form-control" type="text" name="" id="author" placeholder="作者">-->
            <!--<input class="form-control" type="text" name="" id="publisher" placeholder="出版社">-->
            <button class="btn btn-primary" id="search">查询</button>
        </div>
    </div>
    <!--<div class="tgroup">-->
        <!--<button class="btn btn-success" id="addbook" ><span class="glyphicon glyphicon-plus"></span>添加</button>-->
    <!--</div>-->


    <table class="layui-table" id="usertb" lay-filter="usertb">

    </table>



</div>
</body>
</html>
<script>
    $(document).ready(function() {
        layui.use('table', function() {
            var table = layui.table;
            $("#search").click(function () {
                table.reload("usertb",{
                    where :{
                        uname:$("#username").val(),
                        name:$("#name").val(),
                        phone:$("#phone").val()
                    }
                });
            });
            table.render({
                elem: '#usertb',
                url:'/libms/user/list',
                method:"post",
                page:true,
                where :{
                    uname:$("#username").val(),
                    name:$("#name").val(),
                    phone:$("#phone").val()
                },
                cols: [[
                    {field:'uname',  title: '用户名'},
                    {field:'name',  title: '姓名'},
                    {field:'ctime',  title: '创建时间',templet:function (d) {
                        var ctime = new Date(d.ctime)
                        return ctime.getFullYear() + "年" + (ctime.getMonth() + 1) + "月" + ctime.getDate() + "日 " + ctime.getHours() + "点" + ctime.getMinutes() + "分" + ctime.getSeconds() + "秒";;

                        }},
                    {field:'phone',  title: '电话'},
                    {fixed: 'right', width:200, align:'center', toolbar: '#barDemo',  title: '操作'}
                ]]


            });
            //监听工具条
            table.on('tool(usertb)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('ID：'+ data.id + ' 的查看操作');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    // layer.alert('编辑行：<br>'+ JSON.stringify(data))
                    setDate($(".userinput"), data);
                    tc ("/libms/user/update");
                }
            });
        });
        function tc (url) {
            layer.open({
                type: 1,
                content: $('#usermsg'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                btn: ['确定', '取消'],
                btn1: function () {
                    var ac = false;
                    var d = $(".userinput");
                    var data = rDate(d);
                    console.log(data);
                    $.ajax({
                        url: url,
                        type: 'post',
                        dataType: 'json',
                        data: data,
                        async: false
                    }).done(function (e) {
                        if (e.code == 1) {
                            ac = true;
                            table.reload("usertb")
                        } else {
                            alert(e.msg)
                        }
                        console.log("success");
                    })
                        .fail(function () {
                            alert("操作失败")
                        })
                        .always(function () {
                            console.log("complete");
                        });
                    return true;
                },
                end: function () {
                    $(".userinput").val("");
                }

            });
        }
    });

</script>
<script type="text/html" id="barDemo">
     <!--<a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->

</script>